package com.cssy.xxkj.logic.util;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.cssy.authority.service.IScUserRolewhPlaceService;
import com.cssy.xxkj.basic.dao.BasicMaterialsTypeDAO;
import com.cssy.xxkj.basic.dao.BasicProductBomMaterialsDAO;
import com.cssy.xxkj.basic.entity.BasicCompanyTestDO;
import com.cssy.xxkj.basic.entity.BasicMaterialsDO;
import com.cssy.xxkj.basic.entity.BasicMaterialsTypeDO;
import com.cssy.xxkj.basic.entity.BasicStapleUnitDO;
import com.cssy.xxkj.basic.entity.BasicStorageInfoTestDO;
import com.cssy.xxkj.basic.entity.BasicStorageInfoTypeTestDO;
import com.cssy.xxkj.basic.service.IBasicCompanyTestService;
import com.cssy.xxkj.basic.service.IBasicMaterialsBomService;
import com.cssy.xxkj.basic.service.IBasicMaterialsService;
import com.cssy.xxkj.basic.service.IBasicStapleUnitService;
import com.cssy.xxkj.basic.service.IBasicStorageInfoTestService;
import com.cssy.xxkj.basic.service.IBasicStorageInfoTypeTestService;
import com.cssy.xxkj.logic.entity.LogicExcelToStoreDO;
import com.cssy.xxkj.logic.entity.LogicPurchaseWareDO;
import com.cssy.xxkj.logic.entity.LogicPurchaseWareItemDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseDetailsDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseInventoryDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseOtherinDO;
import com.cssy.xxkj.logic.entity.LogicWarehouseOtherinItemDO;
import com.cssy.xxkj.logic.entity.vo.UtilsEntityVO;
import com.cssy.xxkj.logic.service.ILogicExcelToStoreService;
import com.cssy.xxkj.logic.service.ILogicProductionStorageInService;
import com.cssy.xxkj.logic.service.ILogicProductionStorageOutService;
import com.cssy.xxkj.logic.service.ILogicPurchaseWareItemService;
import com.cssy.xxkj.logic.service.ILogicPurchaseWareService;
import com.cssy.xxkj.logic.service.ILogicWareHouseOtherInItemService;
import com.cssy.xxkj.logic.service.ILogicWareHouseOtherInService;
import com.cssy.xxkj.logic.service.ILogicWareHouseOtherOutService;
import com.cssy.xxkj.logic.service.ILogicWarehouseDetailsService;
import com.cssy.xxkj.logic.service.ILogicWarehouseInventoryService;
import com.cssy.xxkj.logic.service.IMaterialOutService;
import com.plat.helper.SearchConditions;
@Service("oftenMapUtil")
public class OftenMapUtil {
	@Resource(name="basicMaterialsTypeDAO")	
	private BasicMaterialsTypeDAO basicMaterialsTypeDAO;
	
	@Resource(name = "basicCompanyTestService")// 客户 or 供应商
	private IBasicCompanyTestService basicCompanyTestService;
	
	@Resource(name="basicMaterialsService")//物料
	private IBasicMaterialsService basicMaterialsService;
	
	@Resource(name="scUserRolePlaceService")
	private IScUserRolewhPlaceService scUserRolePlaceService;
	
	@Resource(name="logicWarehouseDetailsService")
	private ILogicWarehouseDetailsService logicWarehouseDetailsService;
	
	@Resource(name="logicWareHouseOtherInService")//其他入库
	private ILogicWareHouseOtherInService logicWareHouseOtherInService;
	
	@Resource(name="logicWareHouseOtherInItemService")
	private ILogicWareHouseOtherInItemService logicWareHouseOtherInItemService;
	
	@Resource(name="logicWareHouseOtherOutService")//其他出库
	private ILogicWareHouseOtherOutService logicWareHouseOtherOutService;
	
	@Resource(name="logicProductionStorageInService")//成品入库
	private ILogicProductionStorageInService logicProductionStorageInService;
	
	@Resource(name="logicProductionStorageOutService")//成品出库
	private ILogicProductionStorageOutService logicProductionStorageOutService;
	
	//采购入库
	@Resource(name="logicPurchaseWareService")
	private ILogicPurchaseWareService logicPurchaseWareService;
	
	@Resource(name="logicPurchaseWareItemService")
	private ILogicPurchaseWareItemService logicPurchaseWareItemService;
	
	@Resource(name="materialOutServiceImpl")
	private IMaterialOutService materialOutService;
	
	//仓库Service
	@Resource(name = "basicStorageInfoTypeTestService")
	private IBasicStorageInfoTypeTestService basicStorageInfoTypeTestService;
	
	//仓库管理Service
	@Resource(name = "basicStorageInfoTestService")
	private IBasicStorageInfoTestService basicStorageInfoTestService;
	
	//库存明细service
	@Resource(name="logicWarehouseInventoryService")
	private ILogicWarehouseInventoryService logicWarehouseInventoryService; 
	
	@Resource(name = "logicExcelToStoreService")
	private ILogicExcelToStoreService logicExcelToStoreService;
	
	
	@Resource(name="basicMaterialsBomService")//bam
	private IBasicMaterialsBomService basicMaterialsBomService;
	
	@Resource(name="basicProductBomMaterialsDAO")//bom 物品
	private BasicProductBomMaterialsDAO basicProductBomMaterialsDAO;
	
	@Resource(name = "basicStapleUnitService")//单位
	private IBasicStapleUnitService basicStapleUnitService;
	public Map<String, BasicStapleUnitDO> getMaterialUtilById(SearchConditions scs ){
		Map<String, BasicStapleUnitDO> utilsMap= new HashMap<String, BasicStapleUnitDO>();
		List<BasicStapleUnitDO> utilsList= this.basicStapleUnitService.findListByExample(scs).getResults();
		for(BasicStapleUnitDO util:utilsList){
			utilsMap.put(util.getId(), util);
		}
		return utilsMap;
	}
	/**
	 * 采购入库主表
	 * @param scs
	 * @return
	 */
	public Map<String, LogicPurchaseWareDO> getlogicPurchaseWareDOMap(SearchConditions scs ){
		Map<String, LogicPurchaseWareDO> purWareMap= new HashMap<String, LogicPurchaseWareDO>();
		List<LogicPurchaseWareDO> purchaseWareList= this.logicPurchaseWareService.findListByExample(scs).getResults();
		for(LogicPurchaseWareDO ld:purchaseWareList){
			purWareMap.put(ld.getZd003Code(), ld);
		}
		return purWareMap;
	}
	
	/**
	 * 采购入库Item
	 * @param scs
	 * @return
	 */
	public Map<String, LogicPurchaseWareItemDO> getPurWareItemMap(SearchConditions scs){
		Map<String, LogicPurchaseWareItemDO> purWareItemMap= new HashMap<String, LogicPurchaseWareItemDO>();
		List<LogicPurchaseWareItemDO> purWareItemList=this.logicPurchaseWareItemService.findListByExample(scs).getResults();
		for(LogicPurchaseWareItemDO ld:purWareItemList){
			purWareItemMap.put(ld.getZd001PusWareId(), ld);
		}
		return purWareItemMap;
	}
	/**
	 * 其他入库主表信息
	 * @param scs
	 * @return
	 */
	public Map<String, LogicWarehouseOtherinDO> getOtherInDoMap(SearchConditions scs){
		Map<String, LogicWarehouseOtherinDO> otherInMap=new HashMap<String, LogicWarehouseOtherinDO>();
		List<LogicWarehouseOtherinDO> otherInList= this.logicWareHouseOtherInService.findListByExample(scs).getResults();
		for(LogicWarehouseOtherinDO lo:otherInList){
			otherInMap.put(lo.getZd001InCode(), lo);
		}
		return otherInMap;
	}
	/**
	 * 其他入库item
	 * @param scs
	 * @return
	 */
	public Map<String, LogicWarehouseOtherinItemDO> getOtherInItemMap(SearchConditions scs){
		Map<String, LogicWarehouseOtherinItemDO> otherInItemMap= new HashMap<String, LogicWarehouseOtherinItemDO>();
		List<LogicWarehouseOtherinItemDO> otherInItem=this.logicWareHouseOtherInItemService.findListByExample(scs).getResults();
		for(LogicWarehouseOtherinItemDO ld:otherInItem){
			otherInItemMap.put(ld.getZd001OtherInId(), ld);
		}
		return otherInItemMap;
	}
	/**
	 * 出入库明细
	 * @param scs
	 * @return
	 */
	public Map<String, LogicWarehouseDetailsDO> getWarehouseDetailsDOMap(SearchConditions scs){
		 Map<String, LogicWarehouseDetailsDO> warehouseDetailsMap= new HashMap<String, LogicWarehouseDetailsDO>();
		 List<LogicWarehouseDetailsDO> warehouseDetailsList= this.logicWarehouseDetailsService.findListByExample(scs).getResults();
		 for(LogicWarehouseDetailsDO ld:warehouseDetailsList){
			 String key= ld.getZd005MaterialsCode()+"_"+ld.getZd005MaterialsName()+"_"+
					 	 ld.getZd006MaterialsSpec()+"_"+ld.getZd007MaterialsModel()+"_"+
					 	 ld.getZd008MaterialsColor()+"_"+ld.getZd008MaterialsQuanlity()+"_"+
					 	 ld.getZd001BillCode();
			 warehouseDetailsMap.put(key, ld);
		 }
		 return warehouseDetailsMap;
	}
	/**
	 * 库存明细
	 * @param scs
	 * @return
	 */
	public Map<String, LogicWarehouseInventoryDO> getWarehouseInventoryMap(SearchConditions scs){
		Map<String, LogicWarehouseInventoryDO> warehouseInventorMap= new HashMap<String, LogicWarehouseInventoryDO>();
		List<LogicWarehouseInventoryDO> whInvenToryList=this.logicWarehouseInventoryService.findListByExample(scs).getResults();
		for(LogicWarehouseInventoryDO ld:whInvenToryList){
			if("c0829".equals(ld.getZd004MaterialsCode())){
				System.out.println();
			}
			String key=(StringUtils.isEmpty(ld.getZd004MaterialsCode())?null:ld.getZd004MaterialsCode())+"_"+
						(StringUtils.isEmpty(ld.getZd005MaterialsName())?null:ld.getZd005MaterialsName())+"_"+
						(StringUtils.isEmpty(ld.getZd007MaterialsModel())?null:ld.getZd007MaterialsModel())+"_"+
						(StringUtils.isEmpty(ld.getZd006MaterialsSpec())?null:ld.getZd006MaterialsSpec())+"_"+
						(StringUtils.isEmpty(ld.getZd008MaterialsColor())?null:ld.getZd008MaterialsColor())+"_"+
						(StringUtils.isEmpty(ld.getZd008MaterialsQuanlity())?null:ld.getZd008MaterialsQuanlity())+"_"+
						(StringUtils.isEmpty(ld.getZd001WhCode())?null:ld.getZd001WhCode());
			warehouseInventorMap.put(key, ld);
		}
		return warehouseInventorMap;
	}
	/**
	 * 库存明细
	 * @param scs key code name model spec color quanlity picode
	 * @return
	 */
	public Map<String, LogicWarehouseInventoryDO> getStorageMap(SearchConditions scs){
		Map<String, LogicWarehouseInventoryDO> warehouseInventorMap= new HashMap<String, LogicWarehouseInventoryDO>();
		List<LogicWarehouseInventoryDO> whInvenToryList=this.logicWarehouseInventoryService.findListByExample(scs).getResults();
		for(LogicWarehouseInventoryDO ld:whInvenToryList){
			String key=(StringUtils.isEmpty(ld.getZd004MaterialsCode())?null:ld.getZd004MaterialsCode())+"_"+
						(StringUtils.isEmpty(ld.getZd005MaterialsName())?null:ld.getZd005MaterialsName())+"_"+
						(StringUtils.isEmpty(ld.getZd007MaterialsModel())?null:ld.getZd007MaterialsModel())+"_"+
						(StringUtils.isEmpty(ld.getZd006MaterialsSpec())?null:ld.getZd006MaterialsSpec())+"_"+
						(StringUtils.isEmpty(ld.getZd008MaterialsColor())?null:ld.getZd008MaterialsColor())+"_"+
						(StringUtils.isEmpty(ld.getZd008MaterialsQuanlity())?null:ld.getZd008MaterialsQuanlity())+"_"+
						(StringUtils.isEmpty(ld.getZd026PiCode())?null:ld.getZd026PiCode());
			warehouseInventorMap.put(key, ld);
		}
		return warehouseInventorMap;
	}
	/**
	 * 获得所有物料的信息
	 * key的组成  编码+"_"+名称+"_"+规格+"_"+型号+"_"+颜色+"_"+材质
	 * @param scs
	 * @return
	 */
	public Map<String , BasicMaterialsDO> getMaterialMap(SearchConditions scs){
		//获得物料信息
		Map<String , BasicMaterialsDO> materialMap= new HashMap<String , BasicMaterialsDO>();
		List<BasicMaterialsDO> materList = basicMaterialsService.findListByExample(scs).getResults();
		for(BasicMaterialsDO mater:materList){
			if(mater.getId()==null){
				continue;
			}
			String key=mater.getZd001Code()+"_"+mater.getZd002Name()+"_"//编码 名称
					+mater.getZd003Spec()+"_"+mater.getZd004Model()+"_"//规格  型号
					+mater.getZd033Color()+"_"+mater.getZd034Quality();// 颜色  材质
			materialMap.put(key, mater);
		}
		return materialMap;
	}
	public Map<String , BasicStorageInfoTypeTestDO> getStorageType(){
		Map<String , BasicStorageInfoTypeTestDO> tMap=new HashMap<String, BasicStorageInfoTypeTestDO>();
		SearchConditions scs=new SearchConditions();
		scs.setLimitClause(null);
		scs.setLimitPage(false);
		List<BasicStorageInfoTypeTestDO> tList=basicStorageInfoTypeTestService.findListByExample(scs).getResults();
		for(BasicStorageInfoTypeTestDO info :tList){
			tMap.put(info.getId(), info);
		}
		return tMap;
	}
	/**
	 * 获得所有物料的信息
	 * key的组成 code
	 * @param scs
	 * @return
	 */
	public Map<String , BasicMaterialsDO> getMaterialMapByCode(SearchConditions scs){
		//获得物料信息
		Map<String , BasicMaterialsDO> materialMap= new HashMap<String , BasicMaterialsDO>();
		List<BasicMaterialsDO> materList = basicMaterialsService.findListByExample(scs).getResults();
		for(BasicMaterialsDO mater:materList){
			if(mater.getId()==null){
				continue;
			}
			String key=mater.getZd001Code();
			materialMap.put(key, mater);
		}
		return materialMap;
	}/**
	 * 获得所有物料的信息
	 * key的组成 code
	 * @param scs
	 * @return
	 */
	public Map<String , BasicMaterialsDO> getMaterialMapByName(SearchConditions scs){
		//获得物料信息
		Map<String , BasicMaterialsDO> materialMap= new HashMap<String , BasicMaterialsDO>();
		List<BasicMaterialsDO> materList = basicMaterialsService.findListByExample(scs).getResults();
		for(BasicMaterialsDO mater:materList){
			if(mater.getId()==null){
				continue;
			}
			String key=mater.getZd002Name();
			materialMap.put(key, mater);
		}
		return materialMap;
	}
	/**
	 * 获得仓库的信息
	 * key 仓库名称
	 * @param scs
	 * @return
	 */
	public Map<String , BasicStorageInfoTestDO> getStroageInfoMap(SearchConditions scs){
		Map<String , BasicStorageInfoTestDO> wareHouseMap= new HashMap<String, BasicStorageInfoTestDO>();
		List<BasicStorageInfoTestDO> whList=basicStorageInfoTestService.findListByExample(scs).getResults();
		for(BasicStorageInfoTestDO wh:whList){
			wareHouseMap.put(wh.getZd003Name(), wh);
		}
		return wareHouseMap;
	}
	/**
	 * 获得仓库的信息
	 * key 仓库code
	 * @param scs
	 * @return
	 */
	public Map<String , BasicStorageInfoTestDO> getStroageInfoMapKeyCode(SearchConditions scs){
		Map<String , BasicStorageInfoTestDO> wareHouseMap= new HashMap<String, BasicStorageInfoTestDO>();
		List<BasicStorageInfoTestDO> whList=basicStorageInfoTestService.findListByExample(scs).getResults();
		for(BasicStorageInfoTestDO wh:whList){
			wareHouseMap.put(wh.getZd002Code(), wh);
		}
		return wareHouseMap;
	}
	/**
	 * 获得用户或供应商的信息
	 * key 中文名称
	 * @param scs
	 * @return
	 */
	public Map<String , BasicCompanyTestDO> getCurMap(SearchConditions scs){
		Map<String , BasicCompanyTestDO> curMap=new HashMap<String, BasicCompanyTestDO>();
		List<BasicCompanyTestDO> lbc = basicCompanyTestService.findListByExample(scs).getResults();
		for(BasicCompanyTestDO lt:lbc){
			curMap.put(lt.getZd003ZhName(), lt);
		}
		return curMap;
	}
	/**
	 * 物品类别 key 类别名称
	 * @param scs
	 * @return
	 */
	public Map<String , BasicMaterialsTypeDO> getMaterialType(SearchConditions scs){
		Map<String , BasicMaterialsTypeDO> mtMap= new HashMap<String , BasicMaterialsTypeDO>();
		List<BasicMaterialsTypeDO> mtlist= basicMaterialsTypeDAO.find(scs);
		for(BasicMaterialsTypeDO bd:mtlist){
			mtMap.put(bd.getZd002Name(), bd);
		}
		return mtMap;
	}
	/**
	 * 本方法一般和oftenMapUtil.getMaterialMapByCode(scs);配合使用
	 * @param scs
	 * @return
	 */
	public Map<String , BasicMaterialsTypeDO> getMaterialTypeById(SearchConditions scs){
		Map<String , BasicMaterialsTypeDO> mtMap= new HashMap<String , BasicMaterialsTypeDO>();
		List<BasicMaterialsTypeDO> mtlist= basicMaterialsTypeDAO.find(scs);
		for(BasicMaterialsTypeDO bd:mtlist){
			mtMap.put(bd.getId(), bd);
		}
		return mtMap;
	}
	/**
	 * 根据物料编码获得该物品的类型 BasicMaterialsTypeDO  系列
	 * @param scs
	 * @return
	 */
	public Map<String , BasicMaterialsTypeDO> getMaterialTypeKeyMaterialCode(SearchConditions scs){
		Map<String , BasicMaterialsTypeDO> mtMap= new HashMap<String , BasicMaterialsTypeDO>();
		Map<String , BasicMaterialsTypeDO> mTypeMap= new HashMap<String , BasicMaterialsTypeDO>();
		SearchConditions scsM=new SearchConditions();
		scsM.setOrderBy("zd003ParentId");
		scsM.setLimitClause(null);
		scsM.setLimitPage(false);
		List<BasicMaterialsTypeDO> mtlist= basicMaterialsTypeDAO.find(scsM);
		scs.setLimitClause(null);
		scs.setLimitPage(false);
		List<BasicMaterialsDO> bmList=basicMaterialsService.findListByExample(scs).getResults();
		Map<String, String> idAndPIDMap= new HashMap<String, String>();
		Map<String, String> needMap= new HashMap<String, String>();
		for(BasicMaterialsTypeDO bd:mtlist){
			if(bd.getId()==null){
				continue;
			}
			idAndPIDMap.put(bd.getId(), bd.getZd003ParentId());
			mtMap.put(bd.getId(), bd);
		}
		for(String key:idAndPIDMap.keySet()){
			String Pid= this.getPid(idAndPIDMap,  key);
			if(Pid!=null){
				needMap.put(key,Pid);
			}
		}
		for(BasicMaterialsDO mater:bmList){
			if(mater.getId()==null){
				continue;
			}
			String key=mater.getZd029MaterTypeId();//此物品的pId
			String ketType=needMap.get(key);//获得此物品最终的pId
			if(StringUtils.isNotBlank(ketType)){
				BasicMaterialsTypeDO mt=mtMap.get(ketType);
				mTypeMap.put(mater.getZd001Code(),mt);
			}
		}
		return mTypeMap;
	}
	/**
	 * 根据物料编码获得该物品的类型 BasicMaterialsTypeDO  系列
	 * @param scs
	 * @return
	 */
	public Map<String , BasicMaterialsTypeDO> getMaterialTypeKeyMaterialCodeCodition(SearchConditions scs,Map<String , BasicMaterialsDO>  materials){
		Map<String , BasicMaterialsTypeDO> mtMap= new HashMap<String , BasicMaterialsTypeDO>();
		Map<String , BasicMaterialsTypeDO> mTypeMap= new HashMap<String , BasicMaterialsTypeDO>();
		SearchConditions scsM=new SearchConditions();
		scsM.setOrderBy("zd003ParentId");
		scsM.setLimitClause(null);
		scsM.setLimitPage(false);
		List<BasicMaterialsTypeDO> mtlist= basicMaterialsTypeDAO.find(scsM);
		scs.setLimitClause(null);
		scs.setLimitPage(false);
		
		Map<String, String> idAndPIDMap= new HashMap<String, String>();
		Map<String, String> needMap= new HashMap<String, String>();
		for(BasicMaterialsTypeDO bd:mtlist){
			if(bd.getId()==null){
				continue;
			}
			idAndPIDMap.put(bd.getId(), bd.getZd003ParentId());
			mtMap.put(bd.getId(), bd);
		}
		for(String key:idAndPIDMap.keySet()){
			String Pid= this.getPid(idAndPIDMap,  key);
			if(Pid!=null){
				needMap.put(key,Pid);
			}
		}
		for(BasicMaterialsDO mater:materials.values()){
			if(mater.getId()==null){
				continue;
			}
			String key=mater.getZd029MaterTypeId();//此物品的pId
			String ketType=needMap.get(key);//获得此物品最终的pId
			if(StringUtils.isNotBlank(ketType)){
				BasicMaterialsTypeDO mt=mtMap.get(ketType);
				mTypeMap.put(mater.getZd001Code(),mt);
			}
		}
		return mTypeMap;
	}

	private String getPid(Map<String, String> idAndPIDMap, String key) {
		String pid=idAndPIDMap.get(key);//获取父ID
		if(StringUtils.isEmpty(pid)||pid.equals("0")){//父id为0表示他为最顶级（ 材料  成品 之类）
			return  key;
		}else{
			String pid2=idAndPIDMap.get(pid);
			if(StringUtils.isEmpty(pid2)||pid2.equals("0")){
				return  key;
			}else{
				key=this.getPid(idAndPIDMap, pid);
			}
	
		}
		return key;
	}
	
	public Map<String, LogicExcelToStoreDO> getlogicExcelToStoreDOMap(SearchConditions scs){
		Map<String, LogicExcelToStoreDO> etsMap= new HashMap<String, LogicExcelToStoreDO>();
		List<LogicExcelToStoreDO> etsList= this.logicExcelToStoreService.findListByExample(scs).getResults();
		for(LogicExcelToStoreDO le:etsList){
			String keyStr=(StringUtils.isEmpty(le.getZd001MaterialCode())?null:le.getZd001MaterialCode())+"_"+//id
							(StringUtils.isEmpty(le.getZd001MaterialCode())?null:le.getZd001MaterialCode())+"_"+//code
							(StringUtils.isEmpty(le.getZd001MaterialName())?null:le.getZd001MaterialName())+"_"+//name
							(StringUtils.isEmpty(le.getZd002MaterialModel())?null:le.getZd002MaterialModel())+"_"+//model
							(StringUtils.isEmpty(le.getZd003MaterialSpec())?null:le.getZd003MaterialSpec())+"_"+//spec
							null+"_"+//color
							(StringUtils.isEmpty(le.getZd004MaterialTypeName())?null:le.getZd004MaterialTypeName());//quanlity
			LogicExcelToStoreDO ets= etsMap.get(keyStr);
			if(ets==null){
				if(le.getZd010MaterialEndNumber()==null||le.getZd010MaterialEndNumber().compareTo(BigDecimal.ZERO)==0){
					continue;
				}
				etsMap.put(keyStr, le);
			}else{
				le.setZd010MaterialEndMoney((ets.getZd010MaterialEndMoney()==null?BigDecimal.ZERO:ets.getZd010MaterialEndMoney()).add(
						(le.getZd010MaterialEndMoney()==null?BigDecimal.ZERO:le.getZd010MaterialEndMoney())));
				le.setZd010MaterialEndNumber(ets.getZd010MaterialEndNumber().add(
						le.getZd010MaterialEndNumber()==null?BigDecimal.ZERO:le.getZd010MaterialEndNumber()));
				etsMap.put(keyStr, le);
			}
		}
		return etsMap;
	}
	/**
	 * 获取所有维护了bom的物料的bommap
	 * key 为 物料的code
	 * value 为bom的中的物料中的数据
	 */
	public Map<String, List<UtilsEntityVO>> getProductionIDAndBomIdAll(){
		SearchConditions scs = new SearchConditions();
		scs.clearCondition();
		scs.setLimitClause(null);
		scs.setRemovedProperty("bpb.removed");
		scs.setLimitPage(false);
		scs.setOrderBy("bm1.zd001Code ");
		List<UtilsEntityVO> bomMaterList = basicProductBomMaterialsDAO.findAllList(scs);
		Map<String, List<UtilsEntityVO>> bomMap= new HashMap<String, List<UtilsEntityVO>>();
		for(UtilsEntityVO bm:bomMaterList){
			List<UtilsEntityVO> voList= bomMap.get(bm.getBomProCode());
			if(voList==null||voList.isEmpty()||voList.size()==0){
				voList= new ArrayList<UtilsEntityVO>();
			}
			voList.add(bm);
			bomMap.put(bm.getBomProCode(), voList);
		}
		return bomMap;
	}
	
	public Map<String, BasicStapleUnitDO>  getUtilsAllMap(){
		SearchConditions scs= this.getCleanSearchConditions(1);
		List<BasicStapleUnitDO> utilList= this.basicStapleUnitService.findListByExample(scs).getResults();
		Map<String, BasicStapleUnitDO> utilMap = new HashMap<String,BasicStapleUnitDO>();
		for(BasicStapleUnitDO util:utilList){
			utilMap.put(util.getId(), util);
		}
		return utilMap;
	}
	/**
	 * key 为物料编码
	 * @return
	 */
	public Map<String, BasicStapleUnitDO>  getUtilAllMap(){
		Map<String, BasicStapleUnitDO> utilMap=this.getUtilsAllMap();
		SearchConditions scs= this.getCleanSearchConditions(1);
		scs.setRemovedProperty(null);
		List<BasicMaterialsDO> matList=this.basicMaterialsService.findListByExample(scs).getResults();
		for(BasicMaterialsDO mat:matList){
			utilMap.put(mat.getZd001Code(),utilMap.get(mat.getZd007Unit()));
		}
		return utilMap;
	}
	private SearchConditions getCleanSearchConditions(int type){
		SearchConditions scs= new SearchConditions();
		scs.setLimitClause(null);
		scs.setLimitPage(false);
		if(type==0){
			scs.setRemovedProperty(null);
		}
		return scs;
	}
}
